/*
* Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
* Description: util head file
*/

#ifndef UTIL_H
#define UTIL_H

#include "yaml/haf_yaml.h"
#include <opencv2/core/core.hpp>
#include <opencv2/core/utils/filesystem.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <vector>
#include <iostream>
#include <chrono>  // chrono::system_clock
#include <ctime>   // localtime
#include <sstream> // stringstream
#include <iomanip> // put_time
#include <string>  // string
#include <sys/stat.h>

std::string CurrentTimeAndDate();

void yuv420p2nv12(const cv::Mat &yuv420p, cv::Mat &yuv420_nv12, int32_t width, int32_t height);
int32_t getFiles(std::string &path, std::vector<std::string> &files, std::string suffix);
int32_t getFilesBySort(std::string &path, std::vector<std::string> &files, std::string suffix);
time_t convertTimeStr2TimeStamp(std::string timeStr);

class FuncTimeMeasure
{
public:
    FuncTimeMeasure(std::string &&descrip);
    ~FuncTimeMeasure();

private:
    std::string description;
    std::chrono::time_point<std::chrono::steady_clock> start{};
    std::chrono::time_point<std::chrono::steady_clock> end{};
};

struct Config {
    std::string dir{""};
    int32_t instanceId{0};
    int32_t width{0};
    int32_t height{0};
};

class ConfigMangage
{
public:
    ConfigMangage() = default;
    ~ConfigMangage() = default;
    ConfigMangage(std::string configFile) : file(configFile)
    {}
    void Parse();
    std::vector<Config> GetConfig();
    void Show();
    bool CheckConfig();

    inline static bool FileExist(const std::string &name)
    {
        struct stat buffer;
        return (stat(name.c_str(), &buffer) == 0);
    }
private:
    std::string file{"image_config.yaml"};
    std::vector<Config> configs;
};
#endif //UTIL_H
